<?php

/**
 * Description of LeagueDao_Class
 *
 * @author aziz
 */

require_once $_SERVER['DOCUMENT_ROOT'] . '/portal/domain/Country_Class.php';
require_once $_SERVER['DOCUMENT_ROOT'] . '/constants/Constants.php';
require_once 'GenericDAO_Class.php';

class CountryDAO extends GenericDAO {

    public function prepareService($module,$id,$object) {
        $this->type = COUNTRY_SERVICE_MOD;
        $this->module = $module;
        $this->id = $id;
        $this->object=$object;
        $this->__setUp();
    }

    public function loadAll() {
        $start = microtime(true)*1000;
        $this->prepareService(SERVICE_ALL,null,null);
        $ulkeler = $this->getRequest();
        for ($i = 0; $i < count($ulkeler); $i++) {
            $country = new Country();
            $country->setId($ulkeler[$i]->id);
            $country->setName($ulkeler[$i]->name);
            $country->setStatus($ulkeler[$i]->status);

            $countries[] = $country;
        }
        $finish = microtime(true)*1000;
        $this->logger->info("Processing on CountryDAO::loadAll() takes " . substr(($finish - $start),0,4) ." ms");
        return $countries;
    }

    public function loadById($id) {
        $start = microtime(true)*1000;
        $this->prepareService(SERVICE_SINGLE,$id,null);
        $ulke = $this->getRequest();
        $country = new Country();
        $country->setId($ulke->id);
        $country->setName($ulke->name);
        $country->setStatus($ulke->status);
        $country->setShortName($ulke->shortName);
        $country->setAbbreviation($ulke->abbreviation);
        $finish = microtime(true)*1000;
        $this->logger->info("Processing on CountryDAO::loadById($id) takes " . substr(($finish - $start),0,4) ." ms");
        return $country;
    }

    public function delete($id) {
        $start = microtime(true)*1000;
        $this->prepareService(SERVICE_DELETE,$id,null);
        $this->deleteRequest();
        $finish = microtime(true)*1000;
        $this->logger->info("Processing on CountryDAO::delete() takes " . substr(($finish - $start),0,4) ." ms");
    }

    public function upsert($country) {
        $start = microtime(true)*1000;
        $this->prepareService(SERVICE_SAVE,null,$country);
        $this->postRequest();
        $finish = microtime(true)*1000;
        $this->logger->info("Processing on CountryDAO::upsert() takes " . substr(($finish - $start),0,4) ." ms");
    }

}

?>
